﻿package mortal.game.view.copy.groupCopy.view
{
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.button.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.copy.groupCopy.*;
    import mortal.mvc.core.*;

    public class GroupCopyWaitingView extends View
    {
        private var _groupMemberNum:BitmapNumberText;
        private var _sp:GSprite;
        private var _arroundEffect:SWFPlayer;
        private var _brocastBtn:TimeButton;
        private static var _instance:GroupCopyWaitingView;
        public static var openCopy:Boolean = false;

        public function GroupCopyWaitingView()
        {
            this.layer = LayerManager.topLayer;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GroupCopyWaitingLogo, 0, 0, this));
            this._sp = UICompomentPool.getUICompoment(GSprite);
            this._sp.configEventListener(MouseEvent.CLICK, this.openGroupCopyWin);
            this._sp.buttonMode = true;
            this._sp.mouseChildren = false;
            this._sp.mouseEnabled = true;
            this.addChild(this._sp);
            this._arroundEffect = UICompomentPool.getUICompoment(SWFPlayer);
            this._arroundEffect.timeRate = 3;
            this._arroundEffect.move(57, 50);
            this._arroundEffect.load("groupCopyWaiting.swf", ModelType.NormalSwf, null);
            this._sp.addChild(this._arroundEffect);
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GroupCopyWaitingNumBG, 75, 5, this._sp));
            this._groupMemberNum = UIFactory.bitmapNumberText(79, 6, "BasePassWinNum.png", 18, 21, -8, this._sp, 12, 0);
            this._brocastBtn = UIFactory.timeButton(Language.getString(35229), 23, 100, 65, 27, this, "Duiwuzhaomu", "PackButton", false);
            this._brocastBtn.cdTime = 10000;
            this._brocastBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this.updateTeamMate();
            NetDispatcher.addCmdListener(ServerCommand.GroupPlayerInfoChange, this.updateTeamMate);
            Dispatcher.addEventListener(EventName.StageResize, this.stageResizeUpdate);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._groupMemberNum.dispose(param1);
            this._groupMemberNum = null;
            this._sp.dispose(param1);
            this._sp = null;
            this._brocastBtn.dispose(param1);
            this._brocastBtn = null;
            this._arroundEffect.dispose(param1);
            this._arroundEffect = null;
            NetDispatcher.removeCmdListener(ServerCommand.GroupPlayerInfoChange, this.updateTeamMate);
            Dispatcher.removeEventListener(EventName.StageResize, this.stageResizeUpdate);
            super.disposeImpl(param1);
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyGroupRecruit));
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(SceneRange.display.width - 350, 350);
            return;
        }// end function

        private function openGroupCopyWin(event:MouseEvent) : void
        {
            var _loc_2:String = null;
            if (Cache.instance.group.isInDefenseCopyGroup)
            {
                _loc_2 = GroupCopyModule.GroupDefenCopy;
            }
            else if (Cache.instance.group.isInGroupTowerCopy)
            {
                _loc_2 = GroupCopyModule.GroupCopyTower;
            }
            else
            {
                _loc_2 = GroupCopyModule.GroupCopy;
            }
            openCopy = true;
            Dispatcher.dispatchEvent(new DataEvent(EventName.GroupCopyOpenByIndex, _loc_2));
            return;
        }// end function

        private function updateTeamMate(param1:Object = null) : void
        {
            if (!Cache.instance.group.isInCopyGroup)
            {
                this.hide();
                return;
            }
            if (this.isDisposed)
            {
                return;
            }
            var _loc_2:* = Cache.instance.group.players;
            this._groupMemberNum.text = _loc_2.length.toString();
            if (Cache.instance.group.isCaptain && !CopyUtil.isInGroupCopy && Cache.instance.group.sgroup.players.length < 5)
            {
                this._brocastBtn.clickEnble = true;
            }
            else
            {
                this._brocastBtn.clickEnble = false;
            }
            return;
        }// end function

        private function stageResizeUpdate(event:DataEvent) : void
        {
            this.stageResize();
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            this.x = SceneRange.display.width - 350;
            this.y = 350;
            return;
        }// end function

        public static function get instance() : GroupCopyWaitingView
        {
            if (_instance == null)
            {
                _instance = new GroupCopyWaitingView;
            }
            return _instance;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !instance.isHide;
        }// end function

    }
}
